import echarts from 'echarts'
import { unique, max, min } from './request.js'
import $ from 'jquery';

//实验室图表
function initLaboratoryEcharts(list, checkName, arr) {
	let valueFeArr = []; //Y轴 含量
	let BatcnArr = []; //X轴 批次号
	let LSLArr = []; //下限
	let USLArr = []; //上限
	let maxArr = [];
	let kzsxArr = [];
	let kzxxArr = [];
	if(list && list.length > 0){
		list.map(res => {
			if(!res.valueFe){
				res.valueFe = 0;
			}
			if(!res.LSL){
				res.LSL = 0;
			}
			if(!res.USL){
				res.USL = 0;
			}
			valueFeArr.push(res.valueFe);
			BatcnArr.push("批次号：" + res.ProductionLotNO);
			LSLArr.push(res.LSL);
			USLArr.push(res.USL);
			if(arr && arr.length > 0){
				kzsxArr.push(arr[0] + arr[1]);
				kzxxArr.push(arr[0] - arr[1]);
			}
		});
	}
	let firstArr = unique(valueFeArr);
	let secondArr = unique(LSLArr);
	let thirdArr = unique(USLArr);
	if(firstArr && firstArr.length > 0){
		firstArr.map(res => {
			maxArr.push(res);
		});
		secondArr.map(res => {
			maxArr.push(res);
		});
		thirdArr.map(res => {
			maxArr.push(res);
		});
	}
	let maxValue = max(maxArr) || 0;
	let minValue = min(maxArr) || 0;

	let seriesArr = [
		{
			name: '规格下限',
			type:'line',
	        data: LSLArr
		},
		{

			name: '规格上限',
			type:'line',
	        data: USLArr
		},
		{
			name: '含量',
			type:'line',
			data: valueFeArr
		},
		{
			name: '控制上限',
			type: 'line',
			data: kzsxArr
		},
		{
			name: '控制下限',
			type: 'line',
			data: kzxxArr
		}
	];

//	document.getElementById("laboratoryEcharts").clear();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("laboratoryEcharts"))
	let options = {
		title: {
			text: checkName,
			textStyle:{
                fontSize: 15,     //大小
            },
		},
		tooltip: {
	        trigger: 'axis',
//	        axisPointer: {
//              type: 'cross',
//              animation: false,
//              label: {
//                  backgroundColor: '#ccc',
//                  borderColor: '#aaa',
//                  borderWidth: 1,
//                  shadowBlur: 0,
//                  shadowOffsetX: 0,
//                  shadowOffsetY: 0,
//
//                  color: '#222'
//              }
//          },
	    },
	    legend: {
	        data:['规格下限','规格上限','含量','控制上限','控制下限']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '6%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: BatcnArr,
	        splitLine: {
                show: false
            },
	    },
	    yAxis: {
	        type: 'value',
	        scale : true,
//          max : maxValue,
//          min : minValue,
            splitNumber : 30,
            boundaryGap : [ 0.06, 0.06 ],
//          splitLine: {
//              show: false
//          }
	    },
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 30,
			"end": 70,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '120%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#585858"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	    series: seriesArr
	};
	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//Q2
function initLaboratoryIPQCEcharts(list, checkName, arr, formInline) {
	let valueFeArr = []; //Y轴 含量
	let BatcnArr = []; //X轴 批次号
	let LSLArr = []; //下限
	let USLArr = []; //上限
	let maxArr = [];
	let kzsxArr = [];
	let kzxxArr = [];
	if(list && list.length > 0){
		list.map(res => {
			if(!res.valueFe){
				res.valueFe = 0;
			}
			if(!res.LSL){
				res.LSL = 0;
			}
			if(!res.USL){
				res.USL = 0;
			}
			valueFeArr.push(res.valueFe);
			BatcnArr.push("批次号：" + res.PiciNO);
			LSLArr.push(formInline.lsl);
			USLArr.push(formInline.usl);
			if(arr && arr.length > 0){
				kzsxArr.push(parseFloat(arr[0]) + (parseFloat(arr[1]) * 3));
				kzxxArr.push(parseFloat(arr[0]) - (parseFloat(arr[1]) * 3));
			}
		});
	}
	let firstArr = unique(valueFeArr);
	let secondArr = unique(LSLArr);
	let thirdArr = unique(USLArr);
	if(firstArr && firstArr.length > 0){
		firstArr.map(res => {
			maxArr.push(res);
		});
		secondArr.map(res => {
			maxArr.push(res);
		});
		thirdArr.map(res => {
			maxArr.push(res);
		});
	}
	let maxValue = max(maxArr) || 0;
	let minValue = min(maxArr) || 0;

	let seriesArr = [
		{
			name: '规格下限',
			type:'line',
	        data: LSLArr
		},
		{

			name: '规格上限',
			type:'line',
	        data: USLArr
		},
		{
			name: '含量',
			type:'line',
			data: valueFeArr
		},
		{
			name: '控制上限',
			type: 'line',
			data: kzsxArr
		},
		{
			name: '控制下限',
			type: 'line',
			data: kzxxArr
		}
	];

//	document.getElementById("laboratoryEcharts").clear();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("laboratoryEcharts"))
	let options = {
		title: {
			text: checkName,
			textStyle:{
                fontSize: 12,     //大小
            },
		},
		tooltip: {
	        trigger: 'axis',
//	        axisPointer: {
//              type: 'cross',
//              animation: false,
//              label: {
//                  backgroundColor: '#ccc',
//                  borderColor: '#aaa',
//                  borderWidth: 1,
//                  shadowBlur: 0,
//                  shadowOffsetX: 0,
//                  shadowOffsetY: 0,
//
//                  color: '#222'
//              }
//          },
	    },
	    legend: {
	        data:['规格下限','规格上限','含量','控制上限','控制下限']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '6%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: BatcnArr,
	        splitLine: {
                show: false
            },
	    },
	    yAxis: {
	        type: 'value',
	        scale : true,
//          max : maxValue,
//          min : minValue,
            splitNumber : 30,
            boundaryGap : [ 0.06, 0.06 ],
//          splitLine: {
//              show: false
//          }
	    },
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 30,
			"end": 70,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '120%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#585858"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	    series: seriesArr
	};
	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//车间图表
function initProductEcharts(res,index,newpiciTypeArr) {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("echarts" + index))

	let nameList = [];
	let weightList = [];
	let flag = false;
	if(newpiciTypeArr[index] && newpiciTypeArr[index].length > 0){
		newpiciTypeArr[index].forEach(res => {
			if ( res.name !== '车间在制品重量' ) {
				if(res.specificationDescription == "副产品（未合批）"){
					if(res.dayPercentageState == 0 || res.weightPercentageState == 0){
						flag = true;
					}
				}
				nameList.push(res.specificationDescription);
				weightList.push(res.weight);
			}
		})
	}

	let options = {
		title: {
	        text: res,
    	},
		color: ['#3398DB'],
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	return name + " : " + weight + "kg";
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'category',
	            data: nameList,
	            axisTick: {
	                alignWithLabel: true
	            }
	        }
	    ],
	    yAxis: [
	        {
	            type: 'value'
	        }
	    ],
	    series: [
	        {
//	            name: '直接访问',
	            type: 'bar',
	            barWidth: '60%',
	            data: weightList,
	            itemStyle: {
		            color: function(params){
		                var c = '#3398DB';
		                let obj = newpiciTypeArr[index].filter(res => res.specificationDescription == params.name);
		                if(obj && obj.length > 0){
		                	let dayPercentageState = obj[0].dayPercentageState;
		                	let weightPercentageState = obj[0].weightPercentageState;
		                	if(dayPercentageState == 0 || weightPercentageState == 0){
		                		c = '#FF0000'
		                	}
		                }
		                return c;
		            }
		        }
	        }
	    ],
//	    "dataZoom": [{
//			"show": true,
//			"height": 12,
//			"xAxisIndex": [
//				0
//			],
//			bottom: 5,
//			"start": 30,
//			"end": 70,
//			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
//			handleSize: '110%',
//			handleStyle: {
//				color: "#d3dee5",
//			},
//
//			textStyle: {
//				color: "#fff"
//			},
//			borderColor: "rgba(255,255,255,.3)"
//
//		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//车间在制品趋势图
function initWorkShopEcharts(data){
//	let width = $(window).width();
	$("#workShopStatisticsEcharts").show();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("workShopStatisticsEcharts"))

	let nameList = [];
	let valueList = [];
	let pjList = [];
	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			valueList.push(res.weight);
			pjList.push(res.pjWeight);
		});
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	let pjWeight = res[1].value;
	        	var s = '';
	        		s += name + '\n';
					s += "重量 : " + weight + "kg\n";
					s += "平均重量 : " + pjWeight + "kg\n";
					return s;
	        },
	        extraCssText:'width:180px; white-space:pre-wrap',//换行显示
	    },
	    xAxis: {
        type: 'category',
        data: nameList
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [{
	        data: valueList,
	        type: 'line',
	        smooth: true
	    },{
	    	data: pjList,
	    	type: 'line',
	        smooth: true
	    }],
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 0,
			"end": 100,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '110%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#fff"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//仓库趋势图
function initStoreEcharts(data){
	let one = [];
	let two = [];
	let three = [];
	let four = [];
	let five = [];
	let name = [];
	if(data && data.length > 0){
		data.map(res => {
			one.push(res.Qty_A);
			two.push(res.Qty_B);
			three.push(res.Qty_C);
			four.push(res.Qty_D);
			five.push(res.Qty_E);
			name.push(res.ShitName);
		});
	}
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("storeEchart"))

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	var s = '';
	        	if(res && res.length > 0){
	        		res.map((item,index) => {
		        		if(index == 0){
		        			s += item.name + '\n';
		        		}
						s += item.seriesName + ": " + item.value + "kg\n";
	        		});
	        	}
	        	return s;
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	    	top: 30,
	        data: ['<30', '30-60', '60-180', '180-360', '>360']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: name
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [
	        {
	            name: '<30',
	            type: 'line',
	            stack: '总量',
	            data: one
	        },
	        {
	            name: '30-60',
	            type: 'line',
	            stack: '总量',
	            data: two
	        },
	        {
	            name: '60-180',
	            type: 'line',
	            stack: '总量',
	            data: three
	        },
	        {
	            name: '180-360',
	            type: 'line',
	            stack: '总量',
	            data: four
	        },
	        {
	            name: '>360',
	            type: 'line',
	            stack: '总量',
	            data: five
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//合格率趋势图
function initPassRateEcharts(data,line){
//	let width = $(window).width();
//	$("#passRateEcharts").show();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("passRateEcharts"))

	let nameList = [];
	let valueList = [];
	let lineList = [];
	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			valueList.push(res.passRate);
			if(line){
				lineList.push(line);
			}else{
				lineList.push(90);
			}
		});
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
				if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		var s = '';
	        		s += one.name + '\n';
					s += one.seriesName + ' : ' + one.value + '%\n';
					s += two.seriesName + ' : ' + two.value + '%\n';
					return s;
	        	}
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['合格率', '目标值']
	    },
	    xAxis: {
        type: 'category',
        data: nameList
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [
	    	{
	            name: '合格率',
	            type: 'line',
	            data: valueList
	        },{
	            name: '目标值',
	            type: 'line',
	            data: lineList
	        }],
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 0,
			"end": 100,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '110%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#fff"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//生产运行查询趋势图
function initRunQueryEchart(data,line){
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("runQueryEcharts"))

	let nameList = [];
	let productivityList = [];
	let yieldList = [];
	let byProductRateList = [];
	let lineList = [];
	let lYRateList = [];
	if(data && data.length > 0){
		let nameArr = data[0];
		for(let i in nameArr){
			if(i.indexOf("-") != "-1"){
				nameList.push(i);
			}
		}
		if(nameList && nameList.length > 0){
			for(let j in data[0]){
				if(j.indexOf("-") != "-1"){
					productivityList.push(data[0][j]);
					if(line){
						lineList.push(line);
					}else{
						lineList.push(90);
					}
				}
			}
			for(let j in data[1]){
				if(j.indexOf("-") != "-1"){
					yieldList.push(data[1][j]);
				}
			}
			for(let j in data[2]){
				if(j.indexOf("-") != "-1"){
					byProductRateList.push(data[2][j]);
				}
			}
			for(let j in data[4]){
				if(j.indexOf("-") != "-1"){
					lYRateList.push(data[4][j]);
				}
			}
			if(lYRateList.length == 0){
				let length = lineList.length;
				for(let i = 0 ; i < length; i ++ ){
					lYRateList.push(0);
				}
			}
		}
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		let three = res[2];
	        		let four = res[3];
	        		let five = res[4];
	        		var s = '';
	        		s += one.name + '\n';
					s += one.seriesName + ' : ' + one.value + '%\n';
					s += two.seriesName + ' : ' + two.value + '%\n';
					s += three.seriesName + ' : ' + three.value + '%\n';
					s += four.seriesName + ' : ' + four.value + '%\n';
					s += five.seriesName + ' : ' + five.value + '%\n';
					return s;
	        	}
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['产率', '收率', '副产品率', 'SP利用率', '目标值']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: nameList
	    },
	    yAxis: {
	        type: 'value',
	        min: 0
	    },
	    series: [
	        {
	            name: '产率',
	            type: 'line',
//	            stack: '总量',
	            data: productivityList
	        },
	        {
	            name: '收率',
	            type: 'line',
//	            stack: '总量',
	            data: yieldList
	        },
	        {
	            name: '副产品率',
	            type: 'line',
//	            stack: '总量',
	            data: byProductRateList
	        },
	        {
	            name: 'SP利用率',
	            type: 'line',
//	            stack: '总量',
	            data: lYRateList
	        },
	        {
	        	name: '目标值',
	        	type: 'line',
	        	data: lineList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//生产运行查询柱状图
function initRunQueryPillarEcharts(list) {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("runQueryPillarEcharts"))
	//产率，收率，副产品率
	let nameList = ['产率', '收率', '副产品率', '直通率'];
	let valueList = [];
	let productivityClam = 0;
	let yieldClam = 0;
	let byProductRateClam = 0;
	let ZTLYieldClam = 0;
	if(list && list.length > 0){
		list.map(res => {
			let productivity = res.productivity;
			if(productivity){
				if(productivity.indexOf("%") != '-1'){
					productivity = productivity.substring(0, productivity.length - 1);
				}
				productivityClam = productivityClam + parseFloat(productivity);
			}

			let yieldValue = res.yield;
			if(yieldValue){
				if(yieldValue.indexOf("%") != '-1'){
					yieldValue = yieldValue.substring(0, yieldValue.length - 1);
				}
				yieldClam = yieldClam + parseFloat(yieldValue);
			}

			let byProductRate = res.byProductRate;
			if(byProductRate.indexOf("%") != '-1'){
				byProductRate = byProductRate.substring(0, byProductRate.length - 1);
			}
			byProductRateClam = byProductRateClam + parseFloat(byProductRate);

			let ZTLYield = res.ZTLYield;
			if(ZTLYield.indexOf("%") != '-1'){
				ZTLYield = ZTLYield.substring(0, ZTLYield.length - 1);
			}
			ZTLYieldClam = ZTLYieldClam + parseFloat(ZTLYield);
		});
		valueList.push(productivityClam);
		valueList.push(yieldClam);
		valueList.push(byProductRateClam);
		valueList.push(ZTLYieldClam);
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	return name + " : " + weight + "%";
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'category',
	            data: nameList,
	            axisTick: {
	                alignWithLabel: true
	            }
	        }
	    ],
	    yAxis: [
	        {
	            type: 'value'
	        }
	    ],
	    series: [
	        {
	            type: 'bar',
	            barWidth: '60%',
	            itemStyle: {
	            	normal: {
	            		color: function(params){
	            			let colorList = ["#003366","#006699","#4cabce"];
	            			return colorList[params.dataIndex]
	            		}
	            	}
	            },
	            data: valueList
	        }
	    ],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//生产情况汇总表查询趋势图
function initSummaryEchart(data){
//	let width = $(window).width();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("summaryEcharts"))

	let nameList = [];
	let planList = [];
	let trueList = [];
	let differenceList = [];
	let percentList = [];

	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			switch(res.itemName){
				case '1': //计划
					planList.push(res.qty);
				break;
				case '2': //实际
					trueList.push(res.qty);
				break;
				case '3': //差异
					differenceList.push(res.qty);
				break;
				case '4': //达成率
					let item = res.qty;
//					if(res.qty > 0){
//						item = res.qty.toFixed(2);
//					}
					percentList.push(parseFloat(item));
				break;
			}
		});
	}

	nameList = unique(nameList);

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		let three = res[2];
	        		let four = res[3];
	        		var s = '';
	        		s += one.name + '\n';
					s += one.seriesName + ' : ' + one.value + '\n';
					s += two.seriesName + ' : ' + two.value + '\n';
					s += three.seriesName + ' : ' + three.value + '\n';
					return s;
	        	}
	        },
	        extraCssText:'width:150px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['计划', '实际', '差异']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: nameList
	    },
	    yAxis: {
	        type: 'value',
	    },
	    series: [
	        {
	            name: '计划',
	            type: 'line',
	            data: planList
	        },
	        {
	            name: '实际',
	            type: 'line',
	            data: trueList
	        },
	        {
	            name: '差异',
	            type: 'line',
	            data: differenceList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//生产情况汇总表达成率查询趋势图
function initSummaryPercentEchart(data,line){
//	let width = $(window).width();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("summaryPercentEcharts"))

	let nameList = [];
	let percentList = [];
	let lineList = [];

	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			switch(res.itemName){
				case '4': //达成率
					let item = res.qty;
					percentList.push(parseFloat(item));
				break;
			}
			if(line){
				lineList.push(line);
			}else{
				lineList.push(90);
			}
		});
	}

	nameList = unique(nameList);

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		var s = '';
	        		s += one.name + '\n';
					s += one.seriesName + ' : ' + one.value + '%\n';
					s += two.seriesName + ' : ' + two.value + '%\n';
					return s;
	        	}
	        },
	        extraCssText:'width:150px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['达成率','目标值']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: nameList
	    },
	    yAxis: {
	        type: 'value',
	        min: 0,
	    },
	    series: [
	        {
	            name: '达成率',
	            type: 'line',
	            data: percentList
	        },
	        {
	            name: '目标值',
	            type: 'line',
	            data: lineList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//产出情况统计报表
function initConditionEcharts(data) {
	let dayArr = [];
	let itemArr = []; //项目
	let workcenterNameArr = []; //产线
	let productAndPiciTypeArr = []; //产品及工序
	let siteNameArr = []; //车间
	let nameArr = [];
	let seriesArr = [];
	let newDayArr = [];
	if(data && data.length > 0){
		data.map(res => {
			dayArr.push(res.Day);
			if(res.Item != "差异"){
				itemArr.push(res.Item);
				let name = res.SiteName + "*" + res.WorkcenterName + "*" +res.ProductName + res.PiCiType + "*" + res.Item;
				nameArr.push(name);
			}
		});
	}

	//数组去重
	nameArr = unique(nameArr);
	dayArr = unique(dayArr).sort();
	if(dayArr && dayArr.length > 0){
		let t1 = dayArr[0];
		let t2 = dayArr[dayArr.length - 1];
		let t1Arr = t1.split("-");
		let t2Arr = t2.split("-");
		if(t1Arr && t1Arr.length > 0 && t2Arr && t2Arr.length > 0){
			if(t1Arr[0] == t2Arr[0]){
				for(let i = t1Arr[1]; i <= t2Arr[1]; i ++){
					if(i < 10 && i.toString().indexOf("0") == "-1"){
						i = "0" + i;
					}
					newDayArr.push(t1Arr[0] + "-" + i);
				}
			}
		}

		nameArr.map((item,index) => {
			let childrenArr = [];
			newDayArr.map(res => {
				let objArr = data.filter(obj =>
					res == obj.Day && item == obj.SiteName + "*" + obj.WorkcenterName + "*" + obj.ProductName + obj.PiCiType + "*" + obj.Item
				);
				if(objArr && objArr.length > 0){
					if(!objArr[0].Qty){
						objArr[0].Qty = 0;
					}
					objArr.map(it => {
						childrenArr.push(it.Qty);
					});
				}else{
					childrenArr.push(0);
				}
			});
			seriesArr.push({
				name: item,
				type: 'line',
				data: childrenArr
			});
		});
	}

	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("conditionEcharts"))
	// 绘制图表
	myChart.setOption({
//		title: {
//			text: "趋势图"
//		},
		tooltip: {
					trigger: 'axis',
					confine: true
	    },
	    legend: {
	    	type: 'scroll',
	        orient: 'vertical',
	        right: 10,
	        top: 20,
	        bottom: 20,
	        data: nameArr,
	    },
	    grid: {
	        left: '3%',
	        right: '23%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
//	        data: dayArr
			data: newDayArr
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: seriesArr
	});
}

//分时段产出预测报表趋势图
function initDayPartingEcharts(data,shift){
	let name = "";
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("dayPartingEcharts"))

	let planList = [];
	let normalList = [];
	if(data && data.length > 0){
		data.map((res,index) => {
			res.timePlanInventory1 = res.timePlanInventory1 ? res.timePlanInventory1 : 0;
			res.timePlanInventory2 = res.timePlanInventory2 ? res.timePlanInventory2 : 0;
			res.timePlanInventory3 = res.timePlanInventory3 ? res.timePlanInventory3 : 0;
			res.timePlanInventory4 = res.timePlanInventory4 ? res.timePlanInventory4 : 0;
			res.timePlanInventory5 = res.timePlanInventory5 ? res.timePlanInventory5 : 0;
			res.timePlanInventory6 = res.timePlanInventory6 ? res.timePlanInventory6 : 0;
			res.timePlanInventory7 = res.timePlanInventory7 ? res.timePlanInventory7 : 0;
			res.timePlanInventory8 = res.timePlanInventory8 ? res.timePlanInventory8 : 0;
			if(index == 0){
				name = res.workcenterName + " " + res.piciType;
				if(shift == 1){
					planList.push(res.timePlanInventory1);
					planList.push(res.timePlanInventory2);
					planList.push(res.timePlanInventory3);
					planList.push(res.timePlanInventory4);
				}else{
					planList.push(res.timePlanInventory5);
					planList.push(res.timePlanInventory6);
					planList.push(res.timePlanInventory7);
					planList.push(res.timePlanInventory8);
				}
			}
			if(index == 1){
				if(shift == 1){
					normalList.push(res.timePlanInventory1);
					normalList.push(res.timePlanInventory2);
					normalList.push(res.timePlanInventory3);
					normalList.push(res.timePlanInventory4);
				}else{
					normalList.push(res.timePlanInventory5);
					normalList.push(res.timePlanInventory6);
					normalList.push(res.timePlanInventory7);
					normalList.push(res.timePlanInventory8);
				}
			}
		});
	}

	let lineArr = [];
	if(shift == 1){
		lineArr = ['07:30-10:30', '10:30-13:30', '13.30-16.30', '16:30-19:30'];
	}else{
		lineArr = ['19:30-22:30', '22:30-01:30', '01:30-04:30', '04:30-07:30'];
	}

	let options = {
	    title: {
	        text: name
	    },
	    tooltip: {
	        trigger: 'axis'
	    },
	    legend: {
	        data: ['计划', '实际']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: lineArr
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [
	        {
	            name: '计划',
	            type: 'line',
	            data: planList
	        },
	        {
	            name: '实际',
	            type: 'line',
	            data: normalList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//综合管理看板
function initSiteProductEcharts(list) {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("siteProductEchart"))
	//产率，收率，副产品率
	let nameList = ['产率', '收率', '副产品率', '直通率'];
	let valueList = [];
	let productivityClam = 0;
	let yieldClam = 0;
	let byProductRateClam = 0;
	let ZTLYieldClam = 0;
	if(list && list.length > 0){
		list.map(res => {
			let productivity = res.productivity;
			if(productivity){
				if(productivity.indexOf("%") != '-1'){
					productivity = productivity.substring(0, productivity.length - 1);
				}
				productivityClam = productivityClam + parseFloat(productivity);
			}

			let yieldValue = res.yield;
			if(yieldValue){
				if(yieldValue.indexOf("%") != '-1'){
					yieldValue = yieldValue.substring(0, yieldValue.length - 1);
				}
				yieldClam = yieldClam + parseFloat(yieldValue);
			}

			let byProductRate = res.byProductRate;
			if(byProductRate.indexOf("%") != '-1'){
				byProductRate = byProductRate.substring(0, byProductRate.length - 1);
			}
			byProductRateClam = byProductRateClam + parseFloat(byProductRate);

			let ZTLYield = res.ZTLYield;
			if(ZTLYield.indexOf("%") != '-1'){
				ZTLYield = ZTLYield.substring(0, ZTLYield.length - 1);
			}
			ZTLYieldClam = ZTLYieldClam + parseFloat(ZTLYield);
		});
		valueList.push(productivityClam);
		valueList.push(yieldClam);
		valueList.push(byProductRateClam);
		valueList.push(ZTLYieldClam);
	}

	let options = {
		title: {
//	        text: "  单位 %",
//	        textStyle:{
//              fontSize: 12,     //大小
//          },
            subtext:'  单位 %',      //副标题
            subtextStyle:{          //对应样式
                color:'#585858',
                fontSize: 11
            },
    	},
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	return name + " : " + weight + "%";
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'category',
	            data: nameList,
	            axisTick: {
	                alignWithLabel: true
	            }
	        }
	    ],
	    yAxis: [
	        {
	            type: 'value'
	        }
	    ],
	    series: [
	        {
	            type: 'bar',
	            barWidth: '60%',
	            itemStyle: {
	            	normal: {
	            		color: function(params){
	            			let colorList = ["#003366","#006699","#4cabce"];
	            			return colorList[params.dataIndex]
	            		}
	            	}
	            },
	            data: valueList
	        }
	    ],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);

	initSiteProductStyle();
}

function initSiteProductStyle(){
	let width = $(".pOneBk .echartReport .el-col").eq(0).width();
	$(".pOneBk canvas, #siteProductEchart").css("width",width);

	let widthFont = $(".pOneBk .el-row .el-col").eq(1).width();
	if(widthFont < 158){
		$(".POneDesc").css("font-size",parseInt(widthFont / 10) + "px");
		$(".POneDesc li label").css("font-size",parseInt(widthFont / 10) + "px");
	}
	if(widthFont < 140){
		$(".POneDesc").css("margin-left",0);
	}
	if(widthFont >= 156){
		$(".POneDesc").css("font-size","13px");
		$(".POneDesc li label").css("font-size","15px");
	}
}

//副产品趋势图
function initFuProductEcharts(data){
	//	let width = $(window).width();
	$(".byProductEchart").show();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("byProductEchart"))

	let nameList = [];
	let valueList = [];
	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.productionDate);
			valueList.push(res.byProductIdItemQty);
		});
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	var s = '';
	        		s += name + '\n';
					s += "重量 : " + weight + "kg\n";
					return s;
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    xAxis: {
        type: 'category',
        data: nameList
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [{
	        data: valueList,
	        type: 'line',
	        smooth: true
	    }],
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 0,
			"end": 100,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '110%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#fff"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//副产品率趋势图
function initFuPercentEcharts(data){
	//	let width = $(window).width();
	$(".byTimeEchart").show();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("byTimeEchart"))

	let nameList = [];
	let valueList = [];
	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			valueList.push(res.value);
		});
	}

	let options = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	var s = '';
	        		s += name + '\n';
					s += "副产品率 : " + weight + "%\n";
					return s;
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    xAxis: {
        type: 'category',
        data: nameList
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [{
	        data: valueList,
	        type: 'line',
	        smooth: true
	    }],
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 0,
			"end": 100,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '110%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#fff"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
}

//生产情况汇总表查询趋势图
function initPPlanEchart(data){
//	let width = $(window).width();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("pPlanEchart"))

	let nameList = [];
	let planList = [];
	let trueList = [];
	let differenceList = [];
	let percentList = [];

	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			switch(res.itemName){
				case '1': //计划
					planList.push(res.qty);
				break;
				case '2': //实际
					trueList.push(res.qty);
				break;
				case '3': //差异
					differenceList.push(res.qty);
				break;
				case '4': //达成率
					let item = res.qty;
//					if(res.qty > 0){
//						item = res.qty.toFixed(2);
//					}
					percentList.push(parseFloat(item));
				break;
			}
		});
	}

	nameList = unique(nameList);

	let options = {
		title: {
//	        text: "  单位 吨",
//	        textStyle:{
//              fontSize: 12,     //大小
//          },
            subtext:'  单位 吨',      //副标题
            subtextStyle:{          //对应样式
                color:'#585858',
                fontSize: 11
            },
    	},
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		let three = res[2];
	        		let four = res[3];
	        		var s = '';
	        		s += one.name + '\n';
					s += one.seriesName + ' : ' + one.value + '\n';
					s += two.seriesName + ' : ' + two.value + '\n';
					s += three.seriesName + ' : ' + three.value + '\n';
					return s;
	        	}
	        },
	        extraCssText:'width:150px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['计划', '实际', '差异'],
	        top: "3%",
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: nameList
	    },
	    yAxis: {
	        type: 'value',
	    },
	    series: [
	        {
	            name: '计划',
	            type: 'line',
	            data: planList
	        },
	        {
	            name: '实际',
	            type: 'line',
	            data: trueList
	        },
	        {
	            name: '差异',
	            type: 'line',
	            data: differenceList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);

	initPPlanStyle();
}

//根据窗口的大小变动图表
window.onresize = function(){
	initPPlanStyle();
	initSiteProductStyle();
	initPPercentStyle();
	initECarStyle();
	initEFourStyle();
}

function initPPlanStyle(){
	let width = $(".pFourBk .echartReport .el-col").eq(0).width();
	$(".pFourBk .echartReport .el-col").eq(0).find("canvas").css("width",width);
    $("#pPlanEchart").css("width",width);
}

//生产情况汇总表达成率查询趋势图
function initPPercentEchart(data,line){
//	let width = $(window).width();
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("pPlanPercentEchart"))

	let nameList = [];
	let percentList = [];
	let lineList = [];

	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.date);
			switch(res.itemName){
				case '4': //达成率
					let item = res.qty;
					percentList.push(parseFloat(item));
				break;
			}
			if(line){
				lineList.push(line);
			}else{
				lineList.push(90);
			}
		});
	}

	nameList = unique(nameList);

	let options = {
		title: {
//	        text: "  单位 %",
//	        textStyle:{
//              fontSize: 12,     //大小
//          },
			subtext:'  单位 %',      //副标题
            subtextStyle:{          //对应样式
                color:'#585858',
                fontSize: 11
            },
    	},
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	if(res && res.length > 0){
	        		let one = res[0];
	        		let two = res[1];
	        		var s = '';
	        		s += one.name + '\n';
					/*s += one.seriesName + ' : ' + one.value + '%\n';*/
             s += one.seriesName + ' : ' + Math.round(one.value * 100) / 100 + '%\n';
					s += two.seriesName + ' : ' + two.value + '%\n';
					return s;
	        	}
	        },
	        extraCssText:'width:150px; white-space:pre-wrap',//换行显示
	    },
	    legend: {
	        data: ['达成率','目标值'],
	        top: "3%",
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    toolbox: {
	        feature: {
	            saveAsImage: {}
	        }
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: nameList
	    },
	    yAxis: {
	        type: 'value',
	        min: 0,
	    },
	    series: [
	        {
	            name: '达成率',
	            type: 'line',
	            data: percentList
	        },
	        {
	            name: '目标值',
	            type: 'line',
	            data: lineList
	        }
	    ]
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
	initPPercentStyle();
}

function initPPercentStyle(){
	let width = $(".pFourBk .echartReport .el-col").eq(1).width();
	$(".pFourBk .echartReport .el-col").eq(1).find("canvas").css("width",width);
	$("#pPlanPercentEchart").css("width",width);
}

//车间图表
function initECarEcharts(res,index,newpiciTypeArr) {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("EOneEchart"))

	let nameList = [];
	let weightList = [];
	let flag = false;
	if(newpiciTypeArr[index] && newpiciTypeArr[index].length > 0){
		newpiciTypeArr[index].forEach(res => {
			if ( res.name !== '车间在制品重量' ) {
				if(res.specificationDescription == "副产品（未合批）"){
					if(res.dayPercentageState == 0 || res.weightPercentageState == 0){
						flag = true;
					}
				}
				nameList.push(res.specificationDescription);
				weightList.push(res.weight);
			}
		})
	}

	let options = {
		title: {
//	        text: "  单位 KG",
//	        textStyle:{
//              fontSize: 12,     //大小
//          },
			subtext:'  单位 KG',      //副标题
            subtextStyle:{          //对应样式
                color:'#585858',
                fontSize: 11
            },
    	},
		color: ['#3398DB'],
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	return name + " : " + weight + "kg";
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'category',
	            data: nameList,
	            axisTick: {
	                alignWithLabel: true
	            }
	        }
	    ],
	    yAxis: [
	        {
	            type: 'value'
	        }
	    ],
	    series: [
	        {
//	            name: '直接访问',
	            type: 'bar',
	            barWidth: '60%',
	            data: weightList,
	            itemStyle: {
		            color: function(params){
		                var c = '';
		                if(params.dataIndex == 9 && flag){
		                    c = '#FF0000'
		                }else{
		                    c = '#3398DB'
		                }
		                return c;
		            }
		        }
	        }
	    ],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
	initECarStyle();
}

function initECarStyle(){
	let width = $(".eOneCon .echartReport .el-col").eq(0).width();
	$("#EOneEchart canvas").css("width",width);
	$("#EOneEchart").css("width",width);

	let widthTable = $(".eOneCon .echartReport .el-col").eq(1).width();
	widthTable = parseFloat(widthTable);
	if(widthTable < 350){
		$(".EOneTable").css({"marginLeft": 0});
		widthTable = widthTable - 120;
		if(widthTable < 220){
			$(".EOneTable").css({"marginLeft": 0});
			width = width - 30;
		}
	}
	$(".el-table,.EOneTable,.el-table__body-wrapper, .el-table__footer-wrapper, .el-table__header-wrapper").css({"width": width});
	if(widthTable > 350){
		$(".EOneTable").css({"marginLeft": 20});
		$(".EOneTable .el-table,.EOneTable .EOneTable,.EOneTable .el-table__body-wrapper,.EOneTable .el-table__footer-wrapper,.EOneTable .el-table__header-wrapper").css({"width": 210});
	}
}

//副产品趋势图
function initEFourEcharts(data){
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById("EFourEchart"))

	let nameList = [];
	let valueList = [];
	if(data && data.length > 0){
		data.map(res => {
			nameList.push(res.productionDate);
			valueList.push(res.byProductIdItemQty);
		});
	}

	let options = {
		title: {
//	        text: "  单位 KG",
//	        textStyle:{
//              fontSize: 12,     //大小
//          },
			subtext:'  单位 KG',      //副标题
            subtextStyle:{          //对应样式
                color:'#585858',
                fontSize: 11
            },
    	},
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        },
	        formatter: function(res){
	        	let value = res[0];
	        	let name = res[0].name;
	        	let weight = res[0].value;
	        	var s = '';
	        		s += name + '\n';
					s += "重量 : " + weight + "kg\n";
					return s;
	        },
	        extraCssText:'width:120px; white-space:pre-wrap',//换行显示
	    },
	    xAxis: {
        type: 'category',
        data: nameList
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [{
	        data: valueList,
	        type: 'line',
	        smooth: true
	    }],
	    "dataZoom": [{
			"show": true,
			"height": 12,
			"xAxisIndex": [
				0
			],
			bottom: 5,
			"start": 0,
			"end": 100,
			handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
			handleSize: '110%',
			handleStyle: {
				color: "#d3dee5",
			},

			textStyle: {
				color: "#fff"
			},
			borderColor: "rgba(255,255,255,.3)"

		}],
	};

	// 绘制图表
	myChart.clear();
	myChart.setOption(options,true);
	initEFourStyle();
}

function initEFourStyle(){
	let width = $(".EFourBk").width();
	$("#EFourEchart,.EFourBk canvas").css("width",width)
}

export {
	initLaboratoryEcharts,
	initLaboratoryIPQCEcharts,
	initProductEcharts,
	initConditionEcharts,
	initWorkShopEcharts,
	initPassRateEcharts,
	initRunQueryEchart,
	initSummaryEchart,
	initRunQueryPillarEcharts,
	initSummaryPercentEchart,
	initDayPartingEcharts,
	initSiteProductEcharts,
	initFuProductEcharts,
	initPPlanEchart,
	initPPercentEchart,
	initECarEcharts,
	initEFourEcharts,
	initFuPercentEcharts,
	initStoreEcharts
}
